package com.shuoyue.ycgk.ui.common;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.Rule;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import io.reactivex.Observable;

public interface RuleContract {
    interface View extends BaseView {
        void setRule(Rule userInfo);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        /**
         * 1 1分享规则2模考规则3协议学员规则4模考规则
         *
         * @param type
         */
        public void getRule(int type) {
            apply(model.getShareGift(type))
                    .subscribe(new ApiSubscriber<Optional<Rule>>(mView, this,true) {
                        @Override
                        public void onNext(Optional<Rule> lessonProcessOptional) {
                            super.onNext(lessonProcessOptional);
                            mView.setRule(lessonProcessOptional.getIncludeNull());
                        }

                    });
        }
    }

    class Model extends BaseModel {
        Observable<BaseResult<Rule>> getShareGift(int type) {
            return RetrofitClient.getInstance().getApi().getRules(type);
        }
    }
}
